//
//  BeizhuView.m
//  WatermarkCamera
//
//  Created by zhibao on 2023/9/15.
//

#import "BeizhuView.h"
#import "SelectTimeTypeCell.h"
#import "UITextView+YLTextView.h"
@interface BeizhuView(){
    QMUITextView *textView;
    NSString *topTitle;
    NSString *topComntent;
}
@end
@implementation BeizhuView
- (instancetype)initWithTitle:(NSString *)title withContent:(NSString *)content{
    topTitle = title;
    topComntent = content;
    self = [super initWithFrame:CGRectMake(0, MY_Screen_H, MY_Screen_W, MY_Screen_H)];
    if(self){
        self.backgroundColor = MyColorAlpha(@"000000", 0.0);
        [[UIApplication sharedApplication].delegate.window.rootViewController.view addSubview:self];
        [self initView];
    }
    return self;
}

-(void)initView{
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, MY_Screen_H - 557, MY_Screen_W, 64 + 20)];
    topView.layer.cornerRadius = 20;
    topView.backgroundColor = UIColor.whiteColor;
    [self addSubview:topView];
    
    if(topView){
        UILabel *topTitleLabel = [UILabel new];
        topTitleLabel.text = [topTitle stringByReplacingOccurrencesOfString:@":" withString:@""];
        topTitleLabel.font = MY_SCALE_SemiboldFONT(16);
        topTitleLabel.textColor = MYBlock;
        [topView addSubview:topTitleLabel];
        [topTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(topView);
            make.top.mas_equalTo(16);
        }];
        
        UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancelBtn setImage:[UIImage imageNamed:@"com_close_qian"] forState:UIControlStateNormal];
        [topView addSubview:cancelBtn];
        cancelBtn.tag = 1000;
        [cancelBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        cancelBtn.tag = 1000;
        [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(15);
            make.right.mas_equalTo(-15);
        }];
    }
    
    UIView *temView = [[UIView alloc]initWithFrame:CGRectMake(0, topView.bottom - 20, MY_Screen_W , 80)];
    temView.backgroundColor = UIColor.whiteColor;
    [self addSubview:temView];
    
    textView = [[QMUITextView alloc]initWithFrame: CGRectMake(15, topView.top + 64, MY_Screen_W - 30 , 70)];
    textView.backgroundColor = MyColor(@"#F1F1F1");
    textView.placeholder = [NSString stringWithFormat:@"%@%@",LocalizedString(@"请输入"),[topTitle stringByReplacingOccurrencesOfString:@":" withString:@""]];
    textView.limitLength = @(30);
    if(topComntent.length > 0 && ![topComntent isEqualToString:LocalizedString(@"暂无")]&& ![topComntent containsString:LocalizedString(@"请输入")]){
        textView.text = topComntent;
    }
    textView.layer.cornerRadius = 5;
    textView.textContainerInset = UIEdgeInsetsMake(10, 10, 10, 10);
//    textView.text = [GetLocation sharedManager].model.beizhu;
    textView.placeholderColor = MyColor(@"999999");
    textView.maximumTextLength = 30;
    textView.font = MY_SCALE_RegularFONT(13);
    [self addSubview:textView];
    
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, textView.bottom, MY_Screen_W, 557 - 134)];
    bottomView.backgroundColor = UIColor.whiteColor;
    [self addSubview:bottomView];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(15, 20, MY_Screen_W - 30, 46);
    btn.layer.cornerRadius = 23;
    btn.tag = 1001;
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.backgroundColor = MyColor(@"#12BFFF");
    [bottomView addSubview:btn];
    [btn setTitle:LocalizedString(@"完成") forState:UIControlStateNormal];
    btn.titleLabel.font = MY_SCALE_SemiboldFONT(16);
    [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
    
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = MyColorAlpha(@"000000", 0.4);
        self.top = 0;
    }];
    [textView becomeFirstResponder];
}

-(void)btnClick:(UIButton *)btn{
    if(btn.tag == 1000){
        //取消
    }else if(btn.tag == 1001){
        //确定
        if(self.beizhuBlock){
            self.beizhuBlock(textView.text.qmui_trimAllWhiteSpace,topTitle);
        }
    }
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = MyColorAlpha(@"000000", 0.4);
        self.top = MY_Screen_H;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

@end

